<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%@ include file="/view/common/init.jsp"%>
<script type="text/javascript" src="<c:out value="${pageContext.request.contextPath}"/>/js/filter.js"></script>
<script type="text/javascript">
	var countryId = <c:out value="${countryId}"/>;
	var areaId = <c:out value="${areaId}"/>;
	var provinceId = <c:out value="${provinceId}"/>;
	var cellId = <c:out value="${cellId}"/>;
	window.onload = function() {
		new Ajax.Request(base_url + 'agent/cellList.do', {
			method : 'post',
			onSuccess : function(transport) {
				var data = transport.responseText.evalJSON();
				// Init Countries combo
				pushValueToCountryCombo(data.countries);
				
				// Init Area combo
				pushValueToAreaCombo(data.areas);
				
				// Init Province combo
				pushValueToProvinceCombo(data.provinces);	
				
				// Init cell combo
				pushValueToCellCombo(data.agents);
			},
			onFailure : function() {
				alert('Something went wrong...')
			}
		});
	};	
</script>
<title>Quản lý thuê bao</title>
<s:form action="list.do" method="get" name="agentIndexForm">
<center>
	<div class="header">QUẢN LÝ THUÊ BAO</div>
	<div id="comboChoose">
		<div class="item">
			<select name="countryId" id="comboCountry" onchange="filterCountry();" style="width: 130px;">
				<option value="0">--Chọn quốc gia--</option>
			</select>
		</div>
		<div class="item">
			<select name="areaId" id="comboArea" onchange="filterArea();" style="width: 130px;">
				<option value="0">----Chọn miền----</option>
			</select>
		</div>
		<div class="item">
			<select name="provinceId" id="comboProvince" onchange="filterProvince();" style="width: 130px;">
				<option value="0">----Chọn tỉnh----</option>
			</select>
		</div>
		<div class="item">
			<select name="cellId" id="comboCell" style="width: 130px;">
				<option value="0">----Chọn Cell----</option>
			</select>
		</div>
	</div>
	<div class="clear-left"><span></span></div>
	<div id="searchContent">
		<div style="float: right; width: 80px; text-align: right; margin-top: 17px;">
			<button id="bntChoose">Chọn</button>
		</div>		
		<div class="item">
			<div style="margin-bottom: 5px;">Số IMEI</div>
			<input type="text" name="imei" value="<c:out value="${imei}"/>" />
		</div>
		<div class="item">
			<div style="margin-bottom: 5px;">Họ tên</div>
			<input type="text" name="customerId" value="<c:out value="${customerId}"/>" />
		</div>
		<div class="item">
			<div style="margin-bottom: 5px;">Số ĐT(MSISDN)</div>	
			<input type="text" name="msisdn" value="<c:out value="${msisdn}"/>" />	
		</div>		
	</div>
	<div style="width: 980px;margin-top: 80px;">
		<div style="width: 100%;margin-bottom: 10px;">
			<button type="button" onclick="location.href='<c:out value="${pageContext.request.contextPath}"/>/agent/add.do'" style="float: right;">Thêm agent</button>
			<div class="clear-right"><span></span></div>
		</div>  	
		<c:if test='${end != "0"}'> 
		<div style="width: 100%;margin-bottom: 10px;text-align: right;">
			<c:choose>  
				<c:when test='${start != end}'>  
					Bản ghi thứ <c:out value="${start}"/> đến <c:out value="${end}"/>&nbsp;
				</c:when>  
				<c:otherwise>  
					Bản ghi thứ <c:out value="${start}"/>&nbsp;
				</c:otherwise> 
			</c:choose>	 
			trong tổng số <c:out value="${total}"/> bản ghi &nbsp;&nbsp;&nbsp;
			<c:if test='${page != "1"}'> 
				<input type="image" onclick="$('page').value=parseInt($('page').value)-1;return true;" src="<c:out value="${pageContext.request.contextPath}"/>/image/first.png">&nbsp;&nbsp;
			</c:if>
			<c:if test='${pageNum != 1}'>
				<input id="page" readonly="readonly" type="text" name="page" style="width: 30px;text-align: center;" value="<c:out value="${page}"/>">&nbsp;&nbsp;
			</c:if>			<c:if test='${page != pageNum}'> 
				<input type="image" onclick="$('page').value=parseInt($('page').value)+1;return true;"  src="<c:out value="${pageContext.request.contextPath}"/>/image/last.png">
			</c:if>
		</div>
		</c:if>		
	<table class="tbl_info" style="width: 980px;"><tbody>
		<tr>
          <td class="hed">STT</td>
          <td class="hed">Họ tên</td>
          <td class="hed">MSISDN</td>
          <td class="hed"> </td>
          <td class="hed">Sửa</td>
          <td class="hed">Xóa</td>
          <td class="hed">Update_cfg</td>
          <td class="hed">Activate</td>
          <td class="hed">Deactivate</td>
          <td class="hed">Reset</td>
          <td class="hed">Chi tiết mẫu đo</td>
          <td class="hed">Query-config</td>
          <td class="hed">Query-status</td>
          <td class="hed">Measure</td>
        </tr>
      
 	<c:forEach var="agent" items="${agents}" varStatus="rowCounter">
		<tr>
			<td><c:out value="${agent.index}" /></td>
			<td><c:out value="${agent.customerId}" /></td>
			<td><c:out value="${agent.msisdn}" /></td>
			<td><a href="<c:out value="${pageContext.request.contextPath}"/>/agent/view.do?agent.agentId=<c:out value="${agent.agentId}"/>">
				Chi_tiết
			</a></td>
			<td><a class="pic_link" href="<c:out value="${pageContext.request.contextPath}"/>/agent/edit.do?agent.agentId=<c:out value="${agent.agentId}"/>">
			 	<img alt="" src="<c:out value="${pageContext.request.contextPath}"/>/image/b_edit.png" title="Sửa agent"/>
			 </a></td>
			 <td><a class="pic_link" href="#" onclick="deleteAgent(<c:out value="${agent.agentId}"/>);">
			 	<img alt="" src="<c:out value="${pageContext.request.contextPath}"/>/image/b_drop.png" title="Xóa agent"/>
			 </a></td>
			 <td><button type="button" onclick="agentUpdate('update_cfg', <c:out value="${agent.agentId}"/>);" >Update</button></td>  	
			 <td><button type="button" onclick="agentUpdate('activate', <c:out value="${agent.agentId}"/>);"  >Activate</button></td>  	
			 <td><button type="button" onclick="agentUpdate('deactivate', <c:out value="${agent.agentId}"/>);" >Deactivate</button></td>  	
			 <td><button type="button" onclick="agentUpdate('reset', <c:out value="${agent.agentId}"/>);" >Reset</button></td>
 			<td><a href="<c:out value="${pageContext.request.contextPath}"/>/agent/detailExam.do?agent.msisdn=<c:out value="${agent.msisdn}"/>">
				Chi_tiết
			</a></td>
			 <td><button type="button" onclick="agentUpdateQuery('query_config', <c:out value="${agent.agentId}"/>);" >Q-cfg</button></td>  	
			 <td><button type="button" onclick="agentUpdateQuery('query_status', <c:out value="${agent.agentId}"/>);" >Q-status</button></td>  	
			 <td><button type="button" onclick="agentUpdateQuery('measure', <c:out value="${agent.agentId}"/>);" >Measure</button></td>			
		</tr>      		
	</c:forEach>
 </tbody></table>
 </div>
</center>
</s:form>